using System;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Xml;
using System.Xml.Serialization;
using SubSonic;
using SubSonic.Utilities;

//Generated on 24/06/2007 16:38:58 by Rupert

namespace SubSonicMembershipProvider.DataObjects
{
    /// <summary>
    /// Controller class for UserMembership
    /// </summary>
    [System.ComponentModel.DataObject]
    public partial class UserMembershipController
    {
        // Preload our schema..
        UserMembership thisSchemaLoad = new UserMembership();
        private string userName = string.Empty;
        protected string UserName
        {
            get
            {
				if (userName.Length == 0) 
				{
    				if (System.Web.HttpContext.Current != null)
    				{
						userName=System.Web.HttpContext.Current.User.Identity.Name;
					}

					else
					{
						userName=System.Threading.Thread.CurrentPrincipal.Identity.Name;
					}

				}

				return userName;
            }

        }

        [DataObjectMethod(DataObjectMethodType.Select, true)]
        public UserMembershipCollection FetchAll()
        {
            UserMembershipCollection coll = new UserMembershipCollection();
            Query qry = new Query(UserMembership.Schema);
            coll.LoadAndCloseReader(qry.ExecuteReader());
            return coll;
        }

        [DataObjectMethod(DataObjectMethodType.Select, false)]
        public UserMembershipCollection FetchByID(object UserId)
        {
            UserMembershipCollection coll = new UserMembershipCollection().Where("UserId", UserId).Load();
            return coll;
        }

		
		[DataObjectMethod(DataObjectMethodType.Select, false)]
        public UserMembershipCollection FetchByQuery(Query qry)
        {
            UserMembershipCollection coll = new UserMembershipCollection();
            coll.LoadAndCloseReader(qry.ExecuteReader()); 
            return coll;
        }

        [DataObjectMethod(DataObjectMethodType.Delete, true)]
        public bool Delete(object UserId)
        {
            return (UserMembership.Delete(UserId) == 1);
        }

        [DataObjectMethod(DataObjectMethodType.Delete, false)]
        public bool Destroy(object UserId)
        {
            return (UserMembership.Destroy(UserId) == 1);
        }

        
        
        
        [DataObjectMethod(DataObjectMethodType.Delete, true)]
        public bool Delete(int UserId)
        {
            Query qry = new Query(UserMembership.Schema);
            qry.QueryType = QueryType.Delete;
            qry.AddWhere("UserId", UserId);
            qry.Execute();
            return (true);
        }
        
       
    	
    	
	    /// <summary>
	    /// Inserts a record, can be used with the Object Data Source
	    /// </summary>
        [DataObjectMethod(DataObjectMethodType.Insert, true)]
	    public void Insert(string UserName,string LoweredUserName,string MobileAlias,bool IsAnonymous,DateTime LastActivityDate,string Password,int? PasswordFormat,string PasswordSalt,string MobilePIN,string Email,string LoweredEmail,string PasswordQuestion,string PasswordAnswer,bool IsApproved,bool IsLockedOut,DateTime CreateDate,DateTime? LastLoginDate,DateTime? LastPasswordChangedDate,DateTime? LastLockoutDate,int? FailedPasswordAttemptCount,DateTime? FailedPasswordAttemptWindowStart,int FailedPasswordAnswerAttemptCount,DateTime? FailedPasswordAnswerAttemptWindowStart,string Comment)
	    {
		    UserMembership item = new UserMembership();
		    
            item.UserName = UserName;
            
            item.LoweredUserName = LoweredUserName;
            
            item.MobileAlias = MobileAlias;
            
            item.IsAnonymous = IsAnonymous;
            
            item.LastActivityDate = LastActivityDate;
            
            item.Password = Password;
            
            item.PasswordFormat = PasswordFormat;
            
            item.PasswordSalt = PasswordSalt;
            
            item.MobilePIN = MobilePIN;
            
            item.Email = Email;
            
            item.LoweredEmail = LoweredEmail;
            
            item.PasswordQuestion = PasswordQuestion;
            
            item.PasswordAnswer = PasswordAnswer;
            
            item.IsApproved = IsApproved;
            
            item.IsLockedOut = IsLockedOut;
            
            item.CreateDate = CreateDate;
            
            item.LastLoginDate = LastLoginDate;
            
            item.LastPasswordChangedDate = LastPasswordChangedDate;
            
            item.LastLockoutDate = LastLockoutDate;
            
            item.FailedPasswordAttemptCount = FailedPasswordAttemptCount;
            
            item.FailedPasswordAttemptWindowStart = FailedPasswordAttemptWindowStart;
            
            item.FailedPasswordAnswerAttemptCount = FailedPasswordAnswerAttemptCount;
            
            item.FailedPasswordAnswerAttemptWindowStart = FailedPasswordAnswerAttemptWindowStart;
            
            item.Comment = Comment;
            
	    
		    item.Save(UserName);
	    }

    	
	    /// <summary>
	    /// Updates a record, can be used with the Object Data Source
	    /// </summary>
        [DataObjectMethod(DataObjectMethodType.Update, true)]
	    public void Update(int UserId,string UserName,string LoweredUserName,string MobileAlias,bool IsAnonymous,DateTime LastActivityDate,string Password,int? PasswordFormat,string PasswordSalt,string MobilePIN,string Email,string LoweredEmail,string PasswordQuestion,string PasswordAnswer,bool IsApproved,bool IsLockedOut,DateTime CreateDate,DateTime? LastLoginDate,DateTime? LastPasswordChangedDate,DateTime? LastLockoutDate,int? FailedPasswordAttemptCount,DateTime? FailedPasswordAttemptWindowStart,int FailedPasswordAnswerAttemptCount,DateTime? FailedPasswordAnswerAttemptWindowStart,string Comment)
	    {
		    UserMembership item = new UserMembership();
		    
				item.UserId = UserId;
				
				item.UserName = UserName;
				
				item.LoweredUserName = LoweredUserName;
				
				item.MobileAlias = MobileAlias;
				
				item.IsAnonymous = IsAnonymous;
				
				item.LastActivityDate = LastActivityDate;
				
				item.Password = Password;
				
				item.PasswordFormat = PasswordFormat;
				
				item.PasswordSalt = PasswordSalt;
				
				item.MobilePIN = MobilePIN;
				
				item.Email = Email;
				
				item.LoweredEmail = LoweredEmail;
				
				item.PasswordQuestion = PasswordQuestion;
				
				item.PasswordAnswer = PasswordAnswer;
				
				item.IsApproved = IsApproved;
				
				item.IsLockedOut = IsLockedOut;
				
				item.CreateDate = CreateDate;
				
				item.LastLoginDate = LastLoginDate;
				
				item.LastPasswordChangedDate = LastPasswordChangedDate;
				
				item.LastLockoutDate = LastLockoutDate;
				
				item.FailedPasswordAttemptCount = FailedPasswordAttemptCount;
				
				item.FailedPasswordAttemptWindowStart = FailedPasswordAttemptWindowStart;
				
				item.FailedPasswordAnswerAttemptCount = FailedPasswordAnswerAttemptCount;
				
				item.FailedPasswordAnswerAttemptWindowStart = FailedPasswordAnswerAttemptWindowStart;
				
				item.Comment = Comment;
				
		    item.MarkOld();
		    item.Save(UserName);
	    }

    }

}

